package com.thinkgem.javamg.modules.busi.utils;

import com.thinkgem.javamg.common.utils.DateUtils;
import com.thinkgem.javamg.common.utils.StringUtils;
import com.thinkgem.javamg.modules.busi.crawler.CrawSina;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 * 日期转换工具类
 */
public class DateConverUtil {
    protected static Logger logger = LoggerFactory.getLogger(DateConverUtil.class);

    public static Date conver(String sdate) {
        Date date = new Date();
        if (StringUtils.isEmpty(sdate)) {
            return date;
        }
        try {
            //处理yyyy.MM.dd  HH:mm:ss格式
            if (sdate.contains(".")) {
                sdate = sdate.replace(".", "-");
                if (sdate.split("\\:").length == 1) {
                    sdate = sdate + ":00" + ":00";
                }
                if (sdate.split("\\:").length == 2) {
                    sdate = sdate + ":00";
                }
                date = DateUtils.parseDate(sdate, "yyyy-MM-dd HH:mm:ss");
                return date;
            }

            //处理yyyy年MM月dd日 HH:mm格式
            if (sdate.contains("年")) {
                sdate = sdate.replace("年", "-");
                sdate = sdate.replace("月", "-");
                sdate = sdate.replace("日", "");
                if (sdate.split("\\:").length == 1) {
                    sdate = sdate + ":00" + ":00";
                }
                if (sdate.split("\\:").length == 2) {
                    sdate = sdate + ":00";
                }
                date = DateUtils.parseDate(sdate, "yyyy-MM-dd HH:mm:ss");
                return date;
            }

        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return date;
    }

    public static void main(String[] args) throws Exception {
        DateUtils.parseDate("2017-09-14 23:33", "yyyy-MM-dd HH:mm:ss");
    }
}
